package com.gitee.wsl.compose.modifier.animate

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha

@Suppress("ModifierFactoryUnreferencedReceiver")
@Composable
fun Modifier.alphaByEnabled(enabled: Boolean, disabledAlpha: Float = 0.6F): Modifier {
    val value by animateFloatAsState(
        targetValue = if (enabled) 1f else disabledAlpha,
        animationSpec = tween(),
    )
    return alpha(alpha = value)
}